package top.eggcode.system.client.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import top.eggcode.common.mvc.Result;
import top.eggcode.common.mvc.ResultWrapper;
import top.eggcode.system.client.LogClientService;
import top.eggcode.system.client.model.*;

@Component
public class LogClientFactory implements FallbackFactory<LogClientService> {

    private static final Logger logger = LoggerFactory.getLogger(LogClientFactory.class);


    @Override
    public LogClientService create(Throwable cause) {
        logger.error("日志服务调用失败:{}", cause.getMessage());
        return new LogClientService() {
            @Override
            public Result<Boolean> saveToAction(ActionLog log) {
                return ResultWrapper.failure("保存请求日志失败:{}" + cause.getMessage());
            }

            @Override
            public Result<Boolean> saveToException(ExceptionLog log) {
                return ResultWrapper.failure("保存异常日志失败:{}" + cause.getMessage());
            }

            @Override
            public Result<Boolean> saveToFunction(FuncLog log) {
                return ResultWrapper.failure("保存方法日志失败:{}" + cause.getMessage());
            }

            @Override
            public Result<Boolean> saveToLogin(LoginLog log) {
                return ResultWrapper.failure("保存登录日志失败:{}" + cause.getMessage());
            }

            @Override
            public Result<Boolean> saveToStorage(StorageLog log) {
                return ResultWrapper.failure("保存存储日志失败:{}" + cause.getMessage());
            }

            @Override
            public Result<Boolean> saveToVisit(VisitLog log) {
                return ResultWrapper.failure("保存访问日志失败:{}" + cause.getMessage());
            }
        };
    }
}
